package main

import "fmt"
import "os"
import "path/filepath"
import "time"
import "strings"
import "io/ioutil"

var smap map[string]int64

func walkFunc(path string, info os.FileInfo, err error) error {
  var errorRet error
  var arPath []string = strings.Split(path, "\\")
  //if err == nil {
  //  return err
  //}
  value, exists := smap[arPath[0]]
  if !exists {                // New root, set to zero to create
    smap[arPath[0]] = 0
  }
  if !info.Mode().IsDir() {   // Not a directory, so add size
    smap[arPath[0]] = value + info.Size()
  }
  return errorRet
}

func convSize(bytes float64) (float64, string) {
  var typ string = ""
  if bytes > 1024.0 {
    bytes = bytes / 1024.0
    typ = "K"
    if bytes > 1024.0 {
      bytes = bytes / 1024.0
      typ = "M"
      if bytes > 1024.0 {
        bytes = bytes / 1024.0
        typ = "G"
      }
    }
  }
  return bytes, typ
}

func main() {
  t := time.Now()
  var total float64 = 0.0
  var totalType string = ""
  smap = make(map[string]int64)

  files,_ := ioutil.ReadDir(".")
  for _,f := range files {
    fmt.Println(f.Name())
  }

  fmt.Println("dlskfjsdklafjasklfj")
  
  fmt.Println(t)
  filepath.Walk(".", walkFunc)
  // Go through all and print them out
  for key, val := range(smap) {
    var bytes float64 = float64(val)
    var typ string = ""
    var dir string = ""
    //var fi os.FileInfo

    total += bytes

    bytes, typ = convSize(bytes)

    fi,_ := os.Stat(key)

    // If it is a directory, print the eye catcher
    //if err != nil {
    if fi == nil {
      fmt.Println("-=--=-=-=-=-=--==-=-=-= :",key)
    }
    if fi != nil {//err != nil {
      if fi.Mode().IsDir() {
        dir = "<Dir>"
      }
    }

    fmt.Printf("%0.1f%s\t%s\t%s\n", bytes, typ, dir, key)
  }
  // Print total
  total, totalType = convSize(total)
  fmt.Printf("\nTotal Size: %0.1f%s\n", total, totalType)
  fmt.Println(time.Since(t))
}






